package com.openbravo.data.loader;

import com.openbravo.basic.BasicException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

public class MetaSentence extends JDBCSentence
{
  private String m_sSentence;
  protected SerializerRead m_SerRead = null;
  protected SerializerWrite m_SerWrite = null;

  public MetaSentence(Session paramSession, String paramString, SerializerWrite paramSerializerWrite, SerializerRead paramSerializerRead)
  {
    super(paramSession);
    this.m_sSentence = paramString;
    this.m_SerWrite = paramSerializerWrite;
    this.m_SerRead = paramSerializerRead;
  }

  public MetaSentence(Session paramSession, String paramString, SerializerRead paramSerializerRead)
  {
    this(paramSession, paramString, null, paramSerializerRead);
  }

  public DataResultSet openExec(Object paramObject)
    throws BasicException
  {
    closeExec();
    try
    {
      DatabaseMetaData localDatabaseMetaData = this.m_s.getConnection().getMetaData();
      MetaParameter localMetaParameter = new MetaParameter();
      if (paramObject != null)
        this.m_SerWrite.writeValues(localMetaParameter, paramObject);
      if ("getCatalogs".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getCatalogs(), this.m_SerRead);
      if ("getSchemas".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getSchemas(), this.m_SerRead);
      if ("getTableTypes".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getTableTypes(), this.m_SerRead);
      if ("getTypeInfo".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getTypeInfo(), this.m_SerRead);
      if ("getUDTs".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getUDTs(localMetaParameter.getString(0), localMetaParameter.getString(1), null, null), this.m_SerRead);
      if ("getSuperTypes".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getSuperTypes(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2)), this.m_SerRead);
      if ("getAttributes".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getAttributes(localMetaParameter.getString(0), localMetaParameter.getString(1), null, null), this.m_SerRead);
      if ("getTables".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getTables(localMetaParameter.getString(0), localMetaParameter.getString(1), null, null), this.m_SerRead);
      if ("getSuperTables".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getSuperTables(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2)), this.m_SerRead);
      if ("getTablePrivileges".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getTablePrivileges(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2)), this.m_SerRead);
      if ("getBestRowIdentifier".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getBestRowIdentifier(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2), 0, true), this.m_SerRead);
      if ("getPrimaryKeys".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getPrimaryKeys(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2)), this.m_SerRead);
      if ("getColumnPrivileges".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getColumnPrivileges(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2), null), this.m_SerRead);
      if ("getColumns".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getColumns(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2), null), this.m_SerRead);
      if ("getVersionColumns".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getVersionColumns(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2)), this.m_SerRead);
      if ("getIndexInfo".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getIndexInfo(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2), false, false), this.m_SerRead);
      if ("getExportedKeys".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getExportedKeys(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2)), this.m_SerRead);
      if ("getImportedKeys".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getImportedKeys(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2)), this.m_SerRead);
      if ("getCrossReference".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getCrossReference(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2), null, null, null), this.m_SerRead);
      if ("getProcedures".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getProcedures(localMetaParameter.getString(0), localMetaParameter.getString(1), null), this.m_SerRead);
      if ("getProcedureColumns".equals(this.m_sSentence))
        return new JDBCSentence.JDBCDataResultSet(localDatabaseMetaData.getProcedureColumns(localMetaParameter.getString(0), localMetaParameter.getString(1), localMetaParameter.getString(2), null), this.m_SerRead);
      return null;
    }
    catch (SQLException localSQLException)
    { throw new BasicException(localSQLException);
    }
   
  }

  public void closeExec()
    throws BasicException
  {
  }

  public DataResultSet moreResults()
    throws BasicException
  {
    return null;
  }

  private static class MetaParameter
    implements DataWrite
  {
    private ArrayList m_aParams = new ArrayList();

    public void setDouble(int paramInt, Double paramDouble)
      throws BasicException
    {
      throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
    }

    public void setBoolean(int paramInt, Boolean paramBoolean)
      throws BasicException
    {
      throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
    }

    public void setInt(int paramInt, Integer paramInteger)
      throws BasicException
    {
      throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
    }

    public void setString(int paramInt, String paramString)
      throws BasicException
    {
      ensurePlace(paramInt - 1);
      this.m_aParams.set(paramInt - 1, paramString);
    }

    public void setTimestamp(int paramInt, Date paramDate)
      throws BasicException
    {
      throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
    }

    public void setBytes(int paramInt, byte[] paramArrayOfByte)
      throws BasicException
    {
      throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
    }

    public void setObject(int paramInt, Object paramObject)
      throws BasicException
    {
      setString(paramInt, paramObject == null ? null : paramObject.toString());
    }

    public String getString(int paramInt)
    {
      return (String)this.m_aParams.get(paramInt);
    }

    private void ensurePlace(int paramInt)
    {
      this.m_aParams.ensureCapacity(paramInt);
      while (paramInt >= this.m_aParams.size())
        this.m_aParams.add(null);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.loader.MetaSentence
 * JD-Core Version:    0.6.0
 */